<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>申请专家咨询页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="../res/js/tools.js"></script>
    <script src="../res/layui/layui.js"></script>
    <script type="text/javascript">
        $.ajaxSetup({
            async:false
        });
    </script>
</head>
<body>
<form class="layui-form" id="atsfrom">
    <div class="layui-form-item" style="margin-top: 10px">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-inline">
            <input type="hidden" name="schemeId" id="schemeId">
            <input type="text" id="schemeName" name="saName" class="layui-input layui-disabled" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-inline">
            <textarea id="resultExp" name="applyForExp" required lay-verify="resultExp" placeholder="请填写申请理由" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        </div>
    </div>
</form>
<script>
    var form = null;
    layui.use(['form','layedit'], function(){
        form = layui.form
        ,layedit = layui.layedit;
        findAtsScheme();
        //监听提交
        form.on('submit(formDemo)', function(data){
            var formData = new FormData(document.getElementById("atsfrom"));
            var url="../../AtsSchemeActionNutrition/addAtsSchemeExpert";
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.location.reload();
                        });
                    }else{
                        alert(obj.msg);
                    }
                }
            });
            return false;
        })
    })
    function findAtsScheme(){
        var id=getQueryString("id");
        var url = "../../AtsSchemeActionNutrition/findBySchemeId";
        var data = {'id':id};
        $.post(url,data,function(obj){
            console.info(obj);
            $("#schemeName").val(obj.schemeName);
            $("#schemeId").val(obj.schemeId);
            //重新渲染
            form.render();
        },"json");
    }

</script>
</body>
</html>